package com.cb.domain.dao.order.impl;

import java.util.List;
import java.util.ArrayList;
import org.springframework.stereotype.Repository;

import cn.cloud.utils.DateUtil;
import cn.cloud.utils.StringUtils;

import com.cb.core.dao.hibernate.GenericDAOHibernate;
import com.cb.domain.model.order.BOrder;
import com.cb.domain.dao.order.BOrderDAO;
import com.cb.core.webapp.paging.PagingBean;

@Repository
public class BOrderDAOImpl extends GenericDAOHibernate<BOrder, Long> implements BOrderDAO {
	public BOrderDAOImpl() {
		super(BOrder.class);
	}
	
	/**
	 * {@inheritDoc}
	 */
	public List<BOrder> getByVo(BOrder vo, PagingBean pb) {
		List<Object>paramList=new ArrayList<Object>();
		String hql="from BOrder vo where 1=1";
		
		/**TODO 添加自己的需要加入的查询条件
		if(StringUtils.isNotEmpty(vo.getUsername())){
			hql+=" and vo.username like ?";
			paramList.add("%"+vo.getUsername()+"%");
		}**/
		
		List <BOrder>list=this.find(hql, paramList.toArray(), pb);
		return list;
	}

	@Override
	public List<BOrder> getbOrderByTime(String beginTime, String endTime,PagingBean pb) {
		List<Object>paramList=new ArrayList<Object>();
		String hql="from BOrder vo where 1=1 and (vo.status=2 or vo.status=39)";
		if(!StringUtils.isEmpty(beginTime)){
			hql+=" and vo.createTime >= ?";
			paramList.add(DateUtil.getInstance().parseDate2(beginTime));
		}
		if(!StringUtils.isEmpty(endTime)){
			hql+=" and vo.createTime <= ?";
			paramList.add(DateUtil.getInstance().parseDate2(endTime));
		}
		return this.find(hql, paramList.toArray(),pb);
	}

	@Override
	public BOrder findOrderByNo(String orderNo) {
		// TODO Auto-generated method stub
		return (BOrder) this.findUnique("From BOrder where orderNo='"+orderNo+"'", null);
	}
}

